﻿using Gp.AI;
using Gp.Core;
using Gp.Input;
using Gp.Scripts.Core;
using Helpers;
using QFramework;
using TMPro;
using UnityEngine;
using UnityEngine.UI;


namespace Gp.Scripts.GUI.AI {
    public class AIActionInfoWindow : MonoBehaviour, IController {
        public Image icon;
        public TMP_Text title;
        public TMP_Text description;
        public Transform dot;

        private void Start() {
            this.RegisterEvent<AIActionArgs>(DisplayAction);
            this.RegisterEvent<AITurnEndArgs>(ClearUp);
            ClearUp(null);
        }

        private void DisplayAction(AIActionArgs obj) {
            if (!ObjectHelper.MainCamera) return;

            icon.sprite = obj.Icon;
            title.text = obj.Title;
            description.text = obj.Description;
            dot.gameObject.SetActive(true);


            var pos = obj.Unit.transform.position;
            dot.transform.localPosition = InputManager.WorldToUIPosition(transform as RectTransform, pos);
        }

        private void ClearUp(AITurnEndArgs args) {
            icon.sprite = null;
            title.text = "";
            description.text = "";
            dot.gameObject.SetActive(false);
        }

        public IArchitecture GetArchitecture() {
            return MainArchitecture.Interface;
        }
    }
}